﻿//通过XMLHTTP通道不刷新页面从后台取数
//参数：sFile		-	打开文件
//		strType		-	业务类型
//		strGUID		-	业务GUID
//		strTxt		-	其它参数
//		strPostStream		-	大容量业务参数
function GetDataFromXMLHTTP_CstMNG(sFile,strType,strGUID,strTxt,strPostStream)
{
	var rdNum = Math.random();
	var oHTTP = new ActiveXObject("Msxml2.XMLHTTP");
	var strTmp ="";
	
	if (sFile.indexOf("?") == -1)
	{
		strTmp ="?";
	}
	else
	{
		strTmp ="&";
	}
	
	var sUrl = sFile + strTmp + "ywtype=" + escape(strType) + "&ywonlyflag=" + escape(strGUID) + "&ywtxt=" + escape(strTxt) + "&rdnum=" + rdNum; 
		
	if (strPostStream==undefined)
	{
		oHTTP.open( "GET", sUrl, false); 
		oHTTP.send(); 
	}
	else
	{
		oHTTP.open( "POST", sUrl, false); 
		oHTTP.send(strPostStream); 
	}
	
	var bSuccess = handleXMLErr_CstMNG(oHTTP.responseXML); 
	if (bSuccess) 
	{
		if(oHTTP.responseText=="服务器超时") window.navigate("/ErrPage.aspx?errid=001");
		return oHTTP.responseText;	
	}
	else
	{
		alert("取数失败，请与系统管理员联系！");
		return "-1";
	}
}

function handleXMLErr_CstMNG(xml, bContinue)
{
	if (bContinue == null) bContinue = false;
	if (xml.parseError.errorCode != 0)
	{
		alert("XML 错误，请与系统管理员联系");
		if (!bContinue)
		{
			return 0;
		}
		else
		{
			return 2;
		}
	}
	return 1;
}

var lastObj;

//单击tr颜色
//function doTrClick(objTr)
//{
//	if(lastObj==undefined)
//	{
//		lastObj = objTr;
//	}
//	lastObj.style.backgroundColor = "";
//	lastObj = objTr;
//	lastObj.style.backgroundColor = "#CFF3D5";			// 设置选中行背景色
//}

//function OpenQuery()
//{
//	if (Trim(appQueryCtl0.value) == "") return ;
//	
//	if (document.all("txtQueryMemberCard").value != "") 
//	{
//		DoFind("membercard");
//	}
//	
//	if (document.all("txtQueryTel").value != "") DoFind("tel");
//	if (document.all("txtQueryCstName").value != "") DoFind("cstname");
//	if (document.all("txtQueryCardID").value != "") DoFind("cardid"); 
//	
//}

function GetTelType(){
	var radio = document.getElementsByName("TelType");
	var rtnval = 0;
	for(var i=0;i<radio.length;i++)
	{
		if(radio[i].checked)
		{
			rtnval = radio[i].value;
		}
	}
	return rtnval;
}

//查询
function DoFind(sType)
{
	var strReturn;
	
	switch (sType)
	{
		case "membercard":
			if (Trim(document.all("txtQueryMemberCard").value) == "") return;
			
			document.all("txtQueryTel").value = "";
			document.all("txtQueryCstName").value = "";
			document.all("txtQueryCardID").value = "";
			
			if (appQueryCtl0.value == "") return;
			
			DoFindFromTelOrCstName(appQueryCtl0.value,Trim(document.all("txtQueryTel").value),Trim(document.all("txtQueryCstName").value),Trim(document.all("txtQueryCardID").value),document.all("txtQueryMemberCard").value);
			break;
		
		case "cstname":
			document.all("txtQueryMemberCard").value = "";
			document.all("txtQueryTel").value = "";
			document.all("txtQueryCardID").value = "";
			
			if (appQueryCtl0.value == "") return;
			if (Trim(document.all("txtQueryTel").value) == "" && Trim(document.all("txtQueryCstName").value) == "" && Trim(document.all("txtQueryCardID").value) == "") return;
			DoFindFromTelOrCstName(appQueryCtl0.value,Trim(document.all("txtQueryTel").value),Trim(document.all("txtQueryCstName").value),Trim(document.all("txtQueryCardID").value),"");
			break;
				
		case "tel":
			document.all("txtQueryMemberCard").value = "";
			document.all("txtQueryCstName").value = "";
			document.all("txtQueryCardID").value = "";
			
			if (appQueryCtl0.value == "") return;
			if (Trim(document.all("txtQueryTel").value) == "" && Trim(document.all("txtQueryCstName").value) == "" && Trim(document.all("txtQueryCardID").value) == "") return;
		
			DoFindFromTelOrCstName(appQueryCtl0.value,Trim(document.all("txtQueryTel").value),Trim(document.all("txtQueryCstName").value),Trim(document.all("txtQueryCardID").value),"");
			break;
			
		case "cardid":
			document.all("txtQueryMemberCard").value = "";
			document.all("txtQueryTel").value = "";
			document.all("txtQueryCstName").value = "";
			
			if (appQueryCtl0.value == "") return;
			if (Trim(document.all("txtQueryTel").value) == "" && Trim(document.all("txtQueryCstName").value) == "" && Trim(document.all("txtQueryCardID").value) == "") return;
			DoFindFromTelOrCstName(appQueryCtl0.value,Trim(document.all("txtQueryTel").value),Trim(document.all("txtQueryCstName").value),Trim(document.all("txtQueryCardID").value),"");
			break;
	}
}

function DoFindFromCardAndCardID(sMemberCode,sAreaName,sCard,sCardID)
{
	//校验在当前所在项目、业务员为当前操作员（如果选中“允许查询他人客户”不叠加此项过滤）的客户是否存在及是否有重名
	var sQueryOtherFlag = "0" ;
	var sInputRtn = "";
	
	if (document.all("chkIsEnableQueryOthterCst").checked) sQueryOtherFlag = "1";
	
	var strReturn = GetDataFromXMLHTTP_CstMNG("/SLXT/CSTGL/CstMNG_XMLHTTP.aspx","CheckCstFormCardAndCardID",sCard,sCardID,sQueryOtherFlag + sAreaName);
	
	var arrValue = strReturn.split("|");
	
	if (arrValue[0] == "0")
	{
		if(window.confirm(Trim(appQueryCtl0.text)+"项目不存在您跟进的此客户，是否引入会员资料进行跟进？")==false) {return;}
	
		sInputRtn = GetDataFromXMLHTTP_CstMNG("/SLXT/CSTGL/CstMNG_XMLHTTP.aspx","InputHyxtMemberInfoIntoCustomers",sMemberCode,"HyxtAppName|"+sAreaName);
		
		var retValue = sInputRtn.split("|");
		
		if (retValue[0] == "0")
		{
			alert("提示：引入失败！\n"+retValue[1]);
			return ;
		}	
		
		AfterDoFind(sInputRtn);
	}
	else
	{
		AfterDoFind(strReturn);
	}
	
}

function DoFindFromTelOrCstName(sAreaName,sTel,sCstName,sCardID,sMemberCode)
{
	//校验在当前所在项目、业务员为当前操作员（如果选中“允许查询他人客户”不叠加此项过滤）的客户是否存在及是否有重名
	var sQueryOtherFlag = "0" ;
	
	if (document.all("chkIsEnableQueryOthterCst").checked) sQueryOtherFlag = "1";
	var teltype = GetTelType();
	document.frames("CstCmIframe").location = "CstMNG_CmGrid.aspx?membercode=" + escape(sMemberCode) + "&nullquery=1&areaname=" + escape(sAreaName) + "&cstname=" + escape(sCstName) + "&cardid=" + escape(sCardID) + "&tel=" + escape(sTel) + "&queryotherflag=" + escape(sQueryOtherFlag) + "&teltype=" + escape(teltype);
	
	//var sCstInfo = sCstName + "|" + sCardID + "|" + sTel;
	//var strReturn = GetDataFromXMLHTTP_CstMNG("/SLXT/CSTGL/CstMNG_XMLHTTP.aspx","CheckCstFormTelAndName",sCstInfo,sQueryOtherFlag + sAreaName);
	
	//var arrValue = strReturn.split("|");
	
	//if (arrValue[0] == "0")
	//{
	//	alert("该条件下的客户不存在！");
	//	return;
	//}
	
	//AfterDoFind(strReturn);
}

function AfterDoFind(strReturn)
{
   
	var arrValue = strReturn.split("|");
	
	//只有一个满足条件的客户,传递参数,直接打开客户明细资料及其他资料
	if (arrValue[0] == "1")
	{
		document.frames("CstCmIframe").location = "CstMNG_CmGrid.aspx?nullquery=0";
		document.frames("CstDetailIframe").location = "CstMNG_Detail.aspx?cstguid=" + arrValue[1] + "&ywy=&pagemode=2" + "&queryotherflag=" + escape(document.all("txtMemInfoRole").value);
		document.frames("CstOtherInfoIframe").location = "CstMNG_CstReceive.aspx?cstid=" + arrValue[1] + "&meminforole=" + document.all("txtMemInfoRole").value + "&projguid=" + appQueryCtl0.value;
		return;
	}
	
	//存在多个满足条件的客户,刷新重名客户页面
	if (arrValue[0] == "2")
	{
		document.frames("CstCmIframe").location = "CstMNG_CmGrid.aspx?cstguidlist=" + arrValue[1] + "&queryotherflag=" + escape(document.all("txtMemInfoRole").value);	
		document.frames("CstDetailIframe").location = "CstMNG_Detail.aspx?cstguid=&pagemode=2" + "&ywy=&queryotherflag=" + escape(document.all("txtMemInfoRole").value);
		document.frames("CstOtherInfoIframe").location = "CstMNG_CstReceive.aspx?cstid=&meminforole=" + document.all("txtMemInfoRole").value + "&projguid=" + appQueryCtl0.value;
	}
}


//
function showIframCstInfo(obj)
{
	//如果是会员,检测一下该会员以前是否在本地发生业务(如果是本地会员没有业务发生记录则自动增加一条,外地会员返回提示)
	if (obj.memguid != "" && document.all("txtBUGUID").value.toLowerCase() != obj.hjbuguid.toLowerCase())
	{
		var sRtn = GetDataFromXMLHTTP_CstMNG("/SLXT/CSTGL/CstMNG_XMLHTTP.aspx","MemIsFsyw",obj.memguid);
		if (sRtn.substr(0,2) == "NO")
		{
			if (window.confirm("该客户为［" +  sRtn.substr(3) + "］ 籍会员，是否引入进行跟进？") == true)
			{
				//引入该会员
				var sRtn2 = GetDataFromXMLHTTP_CstMNG("/SLXT/CSTGL/CstMNG_XMLHTTP.aspx","MemYrYw",obj.memguid);
				
				if (sRtn2 != "OK")
				{
					alert("系统错误，请关闭重试！");
					return;
				}
			}
			else
			{
				return;
			}
		}
		else if (sRtn != "OK")
		{
			alert("系统错误，请关闭重试！");
			return;
		}
	} 
	
	document.frames("CstDetailIframe").location = "CstMNG_Detail.aspx?oppguid=" + obj.oppguid + "&cstguid=" + obj.cstid + "&ywy=" + obj.ywy +"&ywyguid=" + obj.ywyguid + "&pagemode=2"+ "&queryotherflag=" + escape(document.all("txtMemInfoRole").value);
	document.frames("CstOtherInfoIframe").location = "CstMNG_CstReceive.aspx?oppguid=" + obj.oppguid + "&cstguid=" + obj.cstid + "&meminforole=" + document.all("txtMemInfoRole").value + "&projguid=" + appQueryCtl0.value;
}
